Skip to content

Upgrade Bazel to 9.0.0#21276

Draft
redsun82 wants to merge 10 commits intomainfrom
redsun82/bazel-9
Draft

Upgrade Bazel to 9.0.0#21276
redsun82 wants to merge 10 commits intomainfrom
redsun82/bazel-9

Conversation

@redsun82
Copy link
Contributor

@redsun82 redsun82 commented Feb 5, 2026

Summary

Upgrade Bazel from 8.x to 9.0.0.

Bazel 9 removes native.cc_* and native.java_* rules from Starlark scope, requiring explicit imports from rules_cc and rules_java.

Changes

Core upgrade

  • Upgrade Bazel to 9.0.0 in .bazelversion

New module dependencies

  • rules_cc 0.2.16: provides cc_binary, cc_library, cc_test
  • rules_java 9.0.3: provides java_* rules
  • Update rules_go 0.56.1 → 0.59.0 (Bazel 9 compatibility)
  • Update gazelle 0.40.0 → 0.47.0 (rules_go 0.59.0 compatibility)
  • Update rules_nodejs 6.2.0-codeql.1 → 6.7.3 (upstream version)

Configuration

  • Add +@rules_cc to --incompatible_autoload_externally for graceful migration
  • Register Python 3.12 toolchain (rules_python 1.x requires explicit registration)
  • Disable Android SDK auto-detection (ANDROID_HOME=) to avoid rules_android Bazel 9 compatibility issues

Starlark migrations

  • Add explicit load() statements for cc_binary, cc_library, CcInfo in .bzl files
  • Replace native.cc_* calls with explicit rule names

BUILD file migrations

  • Add explicit load() for cc_binary, cc_library, cc_test from @rules_cc//cc:defs.bzl
  • Add explicit load() for java_library, java_test from @rules_java//java:defs.bzl

C++ runfiles API migration

  • Move from @bazel_tools//tools/cpp/runfiles to @rules_cc//cc/runfiles
  • Update include path and namespace in zipmerge_test.cpp

Fixes

  • Correct malformed JSON in rules_nodejs metadata (trailing comma)

Bazel 9 removes native.cc_* and native.java_* rules from Starlark,
requiring explicit imports from rules_cc and rules_java.
Add explicit dependencies required for Bazel 9:
- rules_cc 0.2.16: provides cc_binary, cc_library, cc_test
- rules_java 9.0.3: provides java_* rules

Also update related dependencies:
- rules_go: 0.56.1 → 0.59.0 (compatibility with Bazel 9)
- gazelle: 0.40.0 → 0.47.0 (compatibility with rules_go 0.59.0)
- rules_nodejs: 6.2.0-codeql.1 → 6.7.3 (upstream version)
rules_python 1.x requires explicit toolchain setup and no longer
auto-registers toolchains. Register Python 3.12 toolchain to ensure
Python tools work correctly with Bazel 9.
Add +@rules_cc to --incompatible_autoload_externally to enable
graceful migration path for cc_* rule usages before all files
are updated with explicit imports.
Bazel 9 removes native.cc_* and CcInfo from global scope. Update:
- swift/rules.bzl: Add cc_binary, cc_library, CcInfo imports; use
  explicit cc_binary/cc_library instead of native.cc_*
- misc/bazel/cmake/cmake.bzl: Add CcInfo import for provider usage
Add explicit load statements for cc_binary, cc_library, and cc_test
from @rules_cc//cc:defs.bzl in:
- shared/cpp/BUILD.bazel
- swift/logging/BUILD.bazel
- misc/bazel/internal/zipmerge/BUILD.bazel
Add explicit load statements for java_library and java_test from
@rules_java//java:defs.bzl in:
- javascript/extractor/BUILD.bazel
- javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel
Bazel 9 moves the C++ runfiles library from @bazel_tools to @rules_cc.
Update:
- zipmerge_test.cpp: Change include from tools/cpp/runfiles to
  rules_cc/cc/runfiles and update namespace accordingly
- BUILD.bazel: Update dependency from @bazel_tools//tools/cpp/runfiles
  to @rules_cc//cc/runfiles
Fix malformed JSON in metadata file - remove trailing comma after
last array element.
@redsun82 redsun82 added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Feb 5, 2026
rules_android has repository visibility issues with Bazel 9 when the
Android SDK is present. Since we don't use Android, disable detection
by setting ANDROID_HOME to empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

depends on internal PR This PR should only be merged in sync with an internal Semmle PR JS Swift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant